package com.hyperzsoft.utils;

import android.content.Context;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;

public class ExpenseGroupDialog extends DialogPreference {
	private ColorSelect colorSelect = null;
	private int lastColor;
	
	public ExpenseGroupDialog(Context context) {
		this(context, null);
	}
	
	public ExpenseGroupDialog(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}
	
	public ExpenseGroupDialog(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		
		setPositiveButtonText("Save");
		setNegativeButtonText("Cancel");
	}
	
	@Override
	protected View onCreateDialogView() {
//		colorListener = new ColorSelectDialog.OnColorChangedListener() {
//			
//			@Override
//			public void colorChanged(String key, int color) {
//				// TODO Auto-generated method stub
//				
//			}
//		};
		
		return colorSelect = new ColorSelect(getContext(), 0);
	}
	
	@Override
	protected void onBindDialogView(View v) {
		super.onBindDialogView(v);
		//
	}
	
	@Override
	protected void onDialogClosed(boolean positiveResult) {
		super.onDialogClosed(positiveResult);
		
		if (positiveResult) {
			if (callChangeListener(colorSelect.getColor())) {
				lastColor= colorSelect.getColor();
				persistInt(colorSelect.getColor());
			}
		}
	}
	
	@Override
	protected Object onGetDefaultValue(TypedArray a, int index) {
		return(a.getInt(index, 0xFFA4C639));
	}
	
	@Override
	protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
		lastColor= (restoreValue ? getPersistedInt(lastColor) : (Integer)defaultValue);
	}
}